Socket
Socket
Sign inDemoInstall

drafter

Package Overview
Dependencies
Maintainers
4
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drafter

Snow Crash parser harness


Version published
Weekly downloads
5.7K
increased by4.29%
Maintainers
4
Weekly downloads
 
Created
Source

Drafter

Circle CI

Snow Crash parser harness.

Introduction

Drafter takes an API blueprint on its input, parses, and then processes the AST to exposes the Parse Result for further use. Drafter expands MSON data structures from the AST and generates JSON representations and JSON Schema representation of MSON structures where they are not found in the original AST.

Installation

Node.js v0.10 is required.

$ npm install -g drafter

Getting Started

Library

var Drafter = require('drafter');
var blueprint = '# GET /message\n' +
                '+ Response 200\n' +
                '\n' +
                '        Hello World!\n'

var drafter = new Drafter;
drafter.make(blueprint, function(error, result) {
    if (error) {
        console.log(error);
        return;
    }

    console.log(JSON.stringify(result, null, 2));
});

CLI Tool

$ cat << 'EOF' > blueprint.apib
# GET /message
+ Response 200

        Hello World!
EOF

$ drafter blueprint.apib

Resolved Named Types

The three rules for when MSON AST is expanded are:

  • If a named type is a sub-type of another named type
  • If a named types includes a mixin
  • If a value member or property member is referencing a named type

The expanded data structures are added to the array which has the original data structures with their element name set to resolvedDataStructure.

Resolved Assets

The resolved assets for a payload body example and payload body schema are added to the array in the content key of the Payload Object with their element name set to resolvedAsset and role in attributes set as bodyExample and bodySchema respectively.

A sample part of payload object is given below

{
  "content": [
    {
      "element": "resolvedAsset",
      "attributes": {
        "role": "bodyExample"
      },
      "content": "{\"id\":\"250FF\",\"percent_off\":25,\"redeem_by\":null}"
    },
    {
      "element": "resolvedAsset",
      "attributes": {
        "role": "bodySchema"
      },
      "content": "{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"},\"percent_off\":{\"type\":\"number\"},\"redeem_by\":{\"type\":\"number\",\"description\":\"Date after which the coupon can no longer be redeemed\"}},\"$schema\":\"http://json-schema.org/draft-04/schema#\"}"
    }
  ]
}

Testing

Inside the drafter repository you can execute the following to run the test suite:

$ npm install
$ npm test

Contribute

Fork & Pull Request.

License

MIT License. See the LICENSE file.

FAQs

Package last updated on 11 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc